//
//  SNCommentCell.m
//  DayDayHappy
//
//  Created by yutao on 14-2-23.
//  Copyright (c) 2014年 yutao. All rights reserved.
//

#import "SNCommentCell.h"
#import "UIImageView+WebCache.h"
#import "NSDate+Helper.h"
#define kCommnetCellWidth   270

@implementation SNCommentCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        anchorImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,15, 30, 30)];
        [anchorImageView setBackgroundColor:[UIColor redColor]];
        [self addSubview:anchorImageView];
        
        //来源
        txtAnchor = [[UILabel alloc]initWithFrame:CGRectMake(anchorImageView.frame.origin.x+anchorImageView.frame.size.width+5,10, 150, 25)];
        [txtAnchor setFont:[UIFont systemFontOfSize:20]];
        [txtAnchor setBackgroundColor:[UIColor whiteColor]];
        [txtAnchor setTextColor:[UIColor colorWithRed:38/255.0 green:38/255.0 blue:38/255.0 alpha:1.0]];
        [self addSubview:txtAnchor];
        
        timeNow = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(txtAnchor.frame) +20, CGRectGetMinY(txtAnchor.frame), 80, 25)];
        [timeNow setTextColor:[UIColor grayColor]];
        [timeNow setTextAlignment:NSTextAlignmentRight];
        [timeNow setFont:[UIFont systemFontOfSize:15]];
        [timeNow setText:@"5分钟前"];
        [self addSubview:timeNow];
        
        //内容
        txtContent = [[UILabel alloc]init];
        [txtContent setBackgroundColor:[UIColor clearColor]];
        [txtContent setFrame:CGRectMake(10, 10, kCommnetCellWidth, 10)];
        [txtContent setFont:[UIFont systemFontOfSize:17]];
        [txtContent setTextColor:[UIColor colorWithRed:83/255.0 green:83/255.0 blue:83/255.0 alpha:1.0]];
        [txtContent setLineBreakMode:NSLineBreakByWordWrapping];
        [self addSubview:txtContent];
        
        lineImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [lineImageView setImage:[UIImage imageNamed:@"line2.png"]];
        [self addSubview:lineImageView];
    }
    return self;
}

-(void)setUpCommentCellWithObject:(SNCommentModel *)commentModel
{
    [txtAnchor setText:commentModel.user_name];
    [txtContent setText:commentModel.content];
    [timeNow setText:[NSDate compareCurrentTime:[NSDate dateFromString:commentModel.created_at]]];
    [anchorImageView setImageWithURL:[NSURL URLWithString:commentModel.icon] placeholderImage:[UIImage imageNamed:@"placeholder"] options:SDWebImageRefreshCached];
    [txtContent setNumberOfLines:0];
    [txtContent setLineBreakMode:NSLineBreakByWordWrapping];
    CGSize sizea = [commentModel.content sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(300, 350) lineBreakMode:NSLineBreakByWordWrapping];
    [txtContent setFrame:CGRectMake(CGRectGetMaxX(anchorImageView.frame) + 5, CGRectGetMaxY(txtAnchor.frame)+2, CGRectGetWidth(txtContent.frame), ceilf(sizea.height))];
    
    lineImageView.frame = CGRectMake(5, CGRectGetMaxY(txtContent.frame) + 20, 310, 2);

    [self setFrame:CGRectMake(10, 0, 300, CGRectGetMaxY(lineImageView.frame))];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
